<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>有效的括号</title>
</head>
<body>
  <script>
    function fn(s) {
      let len = s.length;
      // 一个完整的括号绝对是偶数
      if(len % 2 !== 0 ) return false
      let length = len / 2;
      for (let i = 0; i < length; i++) {
        // 替换方法：一个完整的括号就为空，如果只有一个左/右括号，就不替换保留下来，最后判断长度是否为0
        s = s.replace("()", "");
        s = s.replace("{}", "");
        s = s.replace("[]", "");
      }
      return s.length === 0
    }
    console.log(fn('()()(){}{}{}[]{】'))
  </script>
</body>
</html>